function [ OR ] = makeOR( pa, pg, da, dg, dir)
%makeOR( pa, pg, da, dg, dir) - Make rotational matrix for orientation relation
%   pa, pg - same plane in alpha and gamma
%   da, dg - same direction in alpha and gamma
%   dir: 'a2g' - alpha to gamma, 'g2a' - gamma to alpha
% Example:
%   makeOR([0,1,1]',[1,1,1]',[-1,-1,1]',[-1,0,1]','g2a');


ua = cross(pa,da);
ug = cross(pg,dg);

% From lab to alpha
Ga = [da/norm(da), ua/norm(ua), pa/norm(pa)];
% From lab to gamma
Gg = [dg/norm(dg), ug/norm(ug), pg/norm(pg)];

if (strcmp(dir,'a2g'))
    OR = Gg*Ga';
    %A = OR*pa
    %B = OR*da
elseif (strcmp(dir,'g2a'))
    OR = Ga*Gg';
    %A = OR*pg
    %B = OR*dg
else
    error('Bad direction');
end

end

